<template>
	<view class="order-pages">
		<view class="flex-center flex-column" style="padding:45rpx">
			<i class="iconfont iconjishiwancheng" style="font-size: 130rpx;" :style="{color:primaryColor}"></i>
			<view class="f-mini-title c-title text-bold mt-sm">支付成功</view>
			<view class="c-title mt-md" style="font-size: 54rpx;">-¥{{detail.pay_price || 0}}</view>
		</view>
		<view class="f-mini-title b-1px-t" style="color:#898989;padding:59rpx 55rpx" v-if="detail.id">
			<view class="flex-between">
				<view>订单尾号</view>
				<view class="c-title">
					{{detail.order_code.substring(detail.order_code.length-4, detail.order_code.length)}}
				</view>
			</view>
			<view class="flex-between mt-md">
				<view>订单金额</view>
				<view class="c-title">¥{{detail.total_price}}</view>
			</view>
			<view class="flex-between mt-md" v-if="detail.discount*1 > 0">
				<view>卡券优惠</view>
				<view class="c-warning">-¥{{detail.discount}}</view>
			</view>
			<view class="flex-between mt-md">
				<view>实付金额</view>
				<view class="c-title">¥{{detail.pay_price}}</view>
			</view>

		</view>

		<view class="btn-list flex-center">
			<view @tap.stop="toHome" class="item-child flex-center f-title c-title radius mr-md">回到首页</view>
			<view @tap.stop="toOrderList" class="item-child flex-center f-title c-base radius"
				:style="{background:primaryColor,borderColor:primaryColor}">订单列表</view>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				options: {},
				detail: {
					pay_price: 0
				}
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			order_items_id: state => state.order.order_items_id,
			userInfo: state => state.user.userInfo
		}),
		onLoad(options) {
			this.options = options
			this.initIndex()
		},
		mounted() {
			const mchData = {
				action: "onIframeReady",
				displayStyle: "SHOW_CUSTOM_PAGE",
				height: 900
			};
			const postData = JSON.stringify(mchData);
			window.parent.postMessage(postData, "*")
		},
		methods: {
			...mapActions(['getConfigInfo']),
			...mapMutations(['updateUserItem', 'updateOrderItem']),
			async initIndex(refresh = false) {
				if (!refresh) {
					await this.getConfigInfo()
				}
				let {
					options = {}
				} = this
				alert(JSON.stringify(options))
				if (this.userInfo.id) {
					let {
						order_items_id: id
					} = this
					// id = 5601
					let data = await this.$api.order.orderInfo({
						id
					})
					let {
						init_service_price,
						car_price
					} = data
					data.total_price = (init_service_price * 1 + car_price * 1).toFixed(2)
					this.detail = data
				}
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
			},
			initRefresh() {
				this.initIndex(true)
			},
			toHome() {
				const mchData = {
					action: "jumpOut",
					jumpOutUrl: `https://massage.cncnconnect.com/h5`,
				}
				const postData = JSON.stringify(mchData);
				window.parent.postMessage(postData, "*")
			},
			toOrderList() {
				const mchData = {
					action: "jumpOut",
					jumpOutUrl: `https://massage.cncnconnect.com/h5/?#/user/pages/order/list`,
				}
				const postData = JSON.stringify(mchData);
				window.parent.postMessage(postData, "*")
			}
		}
	}
</script>


<style lang="scss">
	page {
		background: #fff;
	}

	.order-pages {
		.btn-list {
			padding: 80rpx 44rpx 0 44rpx;

			.item-child {
				width: 320rpx;
				height: 96rpx;
				border: 1rpx solid #979797;
				transform: rotateZ(360deg);
			}
		}
	}
</style>